package com.tom;

import com.tom.rpc.v2.RpcClient;
import com.tom.rpc.v2.RpcProxy;
import com.tom.service.IProductService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * 入口
 *
 * @author yanghongjun19
 * @date 2021/01/06
 */
@SpringBootApplication
public class ProductClientApplication {

    @Value("${zookeeper.con}")
    public String zookeeperCon;

    public static void main(String[] args) {
        SpringApplication.run(ProductClientApplication.class, args);
    }


    @Bean
    public RpcDiscover rpcDiscover() {
        try {
            RpcDiscover rpcDiscover = new RpcDiscover(zookeeperCon);
            return rpcDiscover;
        } catch (Exception e) {
            return null;
        }
    }

    @Bean
    public RpcClient rpcClient(RpcDiscover rpcDiscover) {
        return new RpcClient(rpcDiscover);
    }

    @Bean
    public RpcProxy rpcProxy(RpcClient rpcClient) {
        return new RpcProxy(rpcClient);
    }

    @Bean
    public IProductService iProductService(RpcProxy rpcProxy) {
        return rpcProxy.getProxy(IProductService.class);
    }
}
